<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script type='text/javascript' src='../vue.js'></script>
    
</head>
<body>
    <div id="root">
        <h1>今天天气很{{weather}}</h1>
        <br>
        <button @click=changeWeather>点我改变天气</button>
    </div>
    
    <!-- 用计算属性实现 -->
    <script type='text/javascript'>
        new Vue({ 
            el: '#root',
            data: {
                isHot:true,
                weather:''
            },
            methods: {
                changeWeather(){
                    console.log("---changeWeather---")
                    this.isHot = !this.isHot
                }
            },
            // computed:{
            //     weather(){
            //         setTimeout(function(){
            //             console.log(this)
            //             return this.isHot ? '炎热' : '凉爽'
            //         }, 2000);
            //     }
            // }
            watch:{
                isHot:{
                    deep:true,
                    immediate:true, //默认调用一次hander方法
                    handler(v1,v2){
                        console.log(v1,v2)
                        this.weather = v1 ? '炎热' : '凉爽'
                    }
                }
            }
        })
    </script>
    

</body>
</html>